<template>
  <div id="youngDeptList">
    <el-dialog title="设置初审用户" :visible.sync="settingVisible" width="600px" :close-on-click-modal="false" :close-on-press-escape="false">
      <setting @closeDialog="refresh()" :timestamp="timestamp" :unitIdList="ids"></setting>
    </el-dialog>
    <el-dialog title="设置优秀年轻干部模块使用权限" :visible.sync="settingUserVisible" width="600px" :close-on-click-modal="false" :close-on-press-escape="false">
      <settinguser :timestamp="timestamp"></settinguser>
    </el-dialog>
    <el-dialog title="启动填报" :visible.sync="startingVisible" width="600px" :close-on-click-modal="false" :close-on-press-escape="false">
      <starting @closeDialog="startingVisible=false" :timestamp="timestamp" @dialogHide="getList()"></starting>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <!-- <el-breadcrumb-item>人才建设</el-breadcrumb-item> -->
      <el-breadcrumb-item>优秀年轻干部</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
      <h1>优秀年轻干部</h1>
      <el-form :inline="true" :model="filters" v-if="roleShow">
        <div style="padding:22px 22px 0;">
          <el-radio-group v-model="showType" @change="changetype">
            <el-radio-button label="候选库" border>
            </el-radio-button>
            <el-radio-button label="正式库" border>
            </el-radio-button>
          </el-radio-group>
          <el-form-item label="状态" label-width="90px">
            <el-select v-model="filters.state" placeholder="请选择" style="width:120px;">
              <el-option label="全部" value=""></el-option>
              <el-option label="填报" value="0"></el-option>
              <el-option label="初审" value="1"></el-option>
              <el-option label="审查" value="2"></el-option>
              <el-option label="完成" value="3"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="单位名称" label-width="90px">
            <el-input v-model="filters.unitName" style="width:200px;" placeholder="关键字"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" circle @click="search" icon="el-icon-search"></el-button>
            <el-tooltip content="为所选单位设置初审用户" placement="top" v-if="(passStep===2||passStep===3)&&settingUserRole">
              <el-button type="warning" @click="setting" icon="el-icon-setting" circle></el-button>
            </el-tooltip>
            <el-tooltip content="启动填报" placement="top" v-if="(passStep===2||passStep===3)&&settingUserRole">
              <el-button type="success" @click="starting" icon="el-icon-s-flag" circle></el-button>
            </el-tooltip>
            <el-tooltip content="设置优秀年轻干部模块使用权限" placement="top" v-if="this.inRoles('ROLE_youngadmin')">
              <el-button style="color:#000 !important" @click="settinguser" icon="el-icon-user" circle></el-button>
            </el-tooltip>
          </el-form-item>
        </div>
      </el-form>
      <div v-else :style="'color:red;font-weight:bolder;height:'+(tableHeight+150)+'px;padding:25px;font-size:var(--size20) !important'" >当前模块未授权</div>
    </section>
    <section class="wboxd" style="margin-top:10px" v-if="roleShow">
      <!--列表-->
      <el-table :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;" @sort-change='sortChange' :height="tableHeight" border
        @selection-change="handleSelectionChange"
        ref="multipleTable"
        >
        <el-table-column type="index" label="序号" width="50" fixed align="center" class-name="tableth" :index="indexMethod">
        </el-table-column>
        <el-table-column type="selection" width="45" fixed>
        </el-table-column>
        <el-table-column prop="unitName" label="单位" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="state" label="状态" width="110" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{stataText(scope.row.state)}}
          </template>
        </el-table-column>
        <el-table-column prop="submitTime" label="申报时间" width="150" align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="trialTime" label="初审情况" width="220" align="center" show-overflow-tooltip v-if="passStep===2||passStep===3">
          <template slot-scope="scope" v-if="scope.row.trialUser">
            {{scope.row.trialTime}}（{{scope.row.trialUser}}）
          </template>
        </el-table-column>
        <el-table-column prop="retrialTime" label="审查情况" width="220" align="center" show-overflow-tooltip v-if="passStep===2||passStep===3">
          <template slot-scope="scope" v-if="scope.row.retrialUser">
            {{scope.row.retrialTime}}（{{scope.row.retrialUser}}）
          </template>
        </el-table-column>
        <el-table-column prop="trialTime" label="初审人员" width="120" align="center" show-overflow-tooltip v-if="passStep===2||passStep===3">
          <template slot-scope="scope">
            {{scope.row.trialUserName}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="220" align="center">
          <template slot-scope="scope">
            <el-button v-if="scope.row.state===1&&(passStep===1||passStep===3)&&scope.row.trialUserIsCurrentUser" @click="detail(scope.row,1)" type="primary" size="mini" style="margin:10px 0 10px 5px">查看</el-button>
            <el-button v-if="scope.row.state===2&&(passStep===2||passStep===3)" @click="detail(scope.row,1)" type="primary" size="mini" style="margin:10px 0 10px 5px">查看</el-button>
            <el-button v-if="passStep===2||passStep===3" @click="detail(scope.row,2)" size="mini" style="color:#000 !important;margin:10px 0 10px 5px">已完成信息</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" v-if="roleShow">
        <el-pagination style="float:right" :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
import personEdit from './edit'
import setting from './setting'
import settinguser from './settinguser'
import starting from './starting'
export default {
  components: {
    personEdit, setting, starting, settinguser
  },
  data () {
    return {
      startingVisible: false,
      settingVisible: false,
      settingUserVisible: false,
      showType: '候选库',
      moreshow: false,
      exportLoading1: false,
      cllxDic: [],
      wtlyDic: [],
      cljdjgDic: [],
      yxqDic: [],
      roleShow: true,
      roleAdmin: true,
      roleChart: true,
      settype: '',
      userRoles: [],
      setAuthText: '',
      roleSubmitLoading2: false,
      isIndeterminate2: false,
      roleSubmitLoading: false,
      role: [],
      checkAll2: false,
      checkAll: false,
      isIndeterminate: false,
      setRole: false,
      setrole0: false,
      // roles: [{label: '查看', value: 1}, {label: '编辑', value: 2}, {label: '分析', value: 3}],
      roles: ['查看', '编辑', '分析'],
      roles2: [],
      roleuser: [],
      userlist: [],
      processId: '',
      drawer: false,
      authUser: '',
      timestamp: '',
      noRoleCode: '***',
      noRoleText: '***',
      filters: {
        state: '',
        unitName: ''
      },
      listLoading: false,
      ids: [],
      tableHeight: 100,
      list: [
      ],
      pageNum: 1,
      pageSize: 20,
      totalnum: 10,
      item: {},
      dialogtitle: '新增',
      dialogVisible: false,
      readonly: false,
      total: 0,
      Isace: 'asc',
      Sortkey: '',
      changeSizeFlag: false,
      myloading: false,
      passStep: 1,
      settingUserRole: false,
      userRoles0: '' // 举报管理员权限
    }
  },
  methods: {
    indexMethod (index) {
      return index + (this.pageNum - 1) * this.pageSize + 1
    },
    refresh () {
      this.settingVisible = false
      this.getList()
    },
    handleSelectionChange (val) {
      this.ids = val.map(item => item.id)
    },
    stataText (id) {
      switch (id) {
        case 0:
          return '填报'
        case 1:
          return '初审'
        case 2:
          return '审查'
        case 3:
          return '完成'
      }
    },
    checkyoungCadresRole () {
      if (this.inRoles('ROLE_other')) {
        this.$router.push({name: 'youngCadresDept'})
        this.settingUserRole = false
      } else if (this.inRoles('ROLE_sizhang') || this.inRoles('ROLE_fusizhang')) {
        this.passStep = 2
        this.settingUserRole = false
      } else if (this.inRoles('ROLE_chuzhang')) {
        this.passStep = 2
        this.settingUserRole = true
      } else if (this.inRoles('ROLE_banshirenyuan')) {
        this.passStep = 1
        this.settingUserRole = false
      } else if (this.inRoles('ROLE_admin')) {
        this.$router.push({name: 'youngCadresPersonList'})
      }
      if (this.inRoles('ROLE_youngadmin')) {
        this.passStep = 3 // 如果是优秀年轻干部管理员既可以初审又可以复审
      }
    },
    settinguser () {
      this.timestamp = new Date().getTime()
      this.settingUserVisible = true
    },
    setting () {
      if (this.ids.length > 0) {
        this.timestamp = new Date().getTime()
        this.settingVisible = true
      } else {
        this.$message({
          message: '请至少选择一条信息',
          type: 'danger'
        })
      }
    },
    starting () {
      this.timestamp = new Date().getTime()
      this.startingVisible = true
    },
    changetype () {
      if (this.showType === '候选库') {
        this.$router.push({name: 'youngCadresDeptList'})
      } else if (this.showType === '正式库') {
        this.$router.push({name: 'youngCadresPersonList'})
      }
    },
    inRoles (str) {
      let arr = this.userRoles0
      if (arr.indexOf(str) === -1) {
        return false
      } else {
        return true
      }
    },
    detail (data, state) {
      this.$router.push(
        {
          name: 'youngCadresDeptPersonList',
          params: {
            passStep: data.state,
            state: state,
            id: data.id,
            unitname: data.unitName,
            page: {
              unitName: this.filters.unitName,
              state: this.filters.state,
              pageNum: this.pageNum,
              pageSize: this.pageSize,
              orderField: this.Sortkey,
              orderType: this.Isace
            }
          }
        }
      )
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getList()
      }
    },
    // 查询
    search () {
      this.pageNum = 1
      this.getList()
    },
    // 排序
    sortChange: function (column, prop, order) {
      this.Sortkey = column.prop
      if (column.order === 'ascending') {
        this.Isace = 'asc'
      } else {
        this.Isace = 'desc'
      }
      this.getList()
    },
    getList () {
      let deptCode = null
      switch (localStorage.getItem('unitName')) {
        case '干部一处':
          deptCode = 1
          break
        case '干部二处':
          deptCode = 2
          break
        case '干部三处':
          deptCode = 3
          break
      }
      let para = {
        deptCode: deptCode,
        unitName: this.filters.unitName,
        state: this.filters.state,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        orderField: this.Sortkey,
        orderType: this.Isace
      }
      this.listLoading = true
      // var personParams = { Page: 0, Pagenum: 20, Personname: '', Unitkey: '', Sortkey: '', Isace: true, timestamp: new Date().getTime() }
      this.$http
        .post(this.$http.defaults.youngAPI + `api/busUnit/queryPage`, para)
        .then(response => {
          if (response.data.success) {
            this.listLoading = false
            this.list = response.data.result.records
            this.totalnum = response.data.result.total
            this.changeSizeFlag = false
            if ((this.roleuser[0] === 2 || this.roleuser[0] === 3 || this.roleuser[0] === 4) && this.setRole) {
              this.getRoles2()
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      let myheight = 385
      if (this.moreshow) {
        myheight = 385
      } else {
        myheight = 315
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - myheight
      })
    }
  },
  mounted () {
    this.userRoles0 = localStorage.getItem('Roles')
    console.log(this.$route.params.page)
    if (this.$route.params.page) {
      this.filters.unitName = this.$route.params.page.unitName
      this.filters.state = this.$route.params.page.state
      this.pageNum = this.$route.params.page.pageNum
      this.pageSize = this.$route.params.page.pageSize
      this.Sortkey = this.$route.params.page.orderField
      this.Isace = this.$route.params.page.orderType
    }
    this.getList()
    this.checkyoungCadresRole()
    this.tableresize(this)
    window.onresize = () => {
      this.tableresize(this)
    }
  }
}
</script>
<style>
#youngDeptList .el-drawer__wrapper{
  width: 100%;
  height: 100%;
  position: fixed !important;
  overflow: hidden;
}
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  #youngDeptList .el-table td{
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }
</style>
<style scoped>
  #youngDeptList .el-button{
    color:#fff !important;
  }
  #youngDeptList h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #youngDeptList .wboxs{
    width: 100%;
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
    padding:0;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
